<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<script type="text/javascript" src="../public/lib/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="../public/lib/jquery/1.9.1/jquery.min.js"></script>
<#include "lib/lib.html" />
<title>新增优惠券</title>
</head>
<body>
<div class="pd-20">
	<form action="${basePath}/coupon/addCoupon.do" method="post"  class="form form-horizontal" id="form-area-add" enctype="multipart/form-data">
		<div class="row cl">
			<label class="form-label col-3"><span class="c-red">*</span>优惠券名称：</label>
			<div class="formControls col-5">
				<input type="text" class="input-text" id="couponName" name="couponName">
			</div>
			<div class="col-4"> </div>
		</div>
		<div class="row cl">
			<label class="form-label col-3">优惠券图片：</label>
			<div class="formControls col-5">
				  <span class="btn-upload">
				  	<a href="javascript:void();" class="btn btn-primary radius"><i class="iconfont">&#xf0020;</i> 浏览文件</a>
				 	<input type="file" id="fileImage" value="null" name="file" class="input-file" accept="image/png,image/jpg,image/jpeg,imge/bmp,image/gif">
				 </span>
			</div>
			<div class="col-4"> </div>
		</div>
		<div class="row cl">
			<label class="form-label col-3">优惠券价格：</label>
			<div class="formControls col-5">
				<input type="text" class="input-text" id="couponPrice" name="couponPrice">
			</div>
			<div class="col-4"> </div>
		</div>
		<div class="row cl">
			<label class="form-label col-3"><span class="c-red">*</span>有效时间：</label>
			<div class="formControls col-5">
				<input type="text" onfocus="WdatePicker({ dateFmt:'yyyy-MM-dd'})" id="commentdatemin" name="startTime" class="input-text Wdate" style="width:180px;">
				-
				<input type="text" onfocus="WdatePicker({ dateFmt:'yyyy-MM-dd',minDate:'#F{$dp.$D(\'commentdatemin\')}' })" id="commentdatemax" name="endTime" class="input-text Wdate" style="width:180px;">
			</div>
			<div class="col-4"> </div>
		</div>
		<div class="row cl">
			<label class="form-label col-3">每个用户可领个数：</label>
			<div class="formControls col-5">
				<input type="text" class="input-text" value="" placeholder="0表示不限制" id="userCount" name="userCount">
			</div>
			<div class="col-4"> </div>
		</div>
		<div class="row cl">
			<label class="form-label col-3"><span class="c-red">*</span>优惠券总个数：</label>
			<div class="formControls col-5">
				<input type="text" class="input-text" id="couponCount" name="couponCount">
			</div>
			<div class="col-4"> </div>
		</div>
		<div class="row cl">
			<label class="form-label col-3">使用类型：</label>
			<div class="formControls col-5">
				<div class="radio-box">
					<input name="ccouponUsetype" type="radio" onclick="priceN(1)" value="1" checked>
					<label for="sex-1">价格</label>
				</div>
				<div class="radio-box">
					<input name="ccouponUsetype" type="radio" value="2" onclick="priceN(2)" >
					<label for="sex-2">时间区</label>
				</div>
				<div class="radio-box">
					<input name="ccouponUsetype" type="radio" value="10" onclick="priceN(10)">
					<label for="sex-2">无限制</label>
				</div>
			</div>
			<div class="col-4"> </div>
		</div>
		<div class="row cl" id="priceP">
			<label class="form-label col-3">类型参数：</label>
			<div class="formControls col-5">
				<input type="text" class="input-text" id="ccouponUseparam" name="ccouponUseparam">
			</div>
			<div class="col-4"> </div>
		</div>
		<div class="row cl" id="timeP" style="display: none">
			<label class="form-label col-3">类型参数：</label>
			<div class="formControls col-5">
				<input type="text" onfocus="WdatePicker({ dateFmt:'yyyy-MM-dd'})" id="logmin" name="startParam" class="input-text Wdate" style="width:180px;">
				-
				<input type="text" onfocus="WdatePicker({ dateFmt:'yyyy-MM-dd',minDate:'#F{$dp.$D(\'logmin\')}' })" id="logmax" name="endParam" class="input-text Wdate" style="width:180px;">
			</div>
			<div class="col-4"> </div>
		</div>
		<div class="row cl">
			<label class="form-label col-3">描述：</label>
			<div class="formControls col-5">
				<textarea rows="8" cols="45" id="couponDesc" name="couponDesc"></textarea>
			</div>
			<div class="col-4"> </div>
		</div>
		<div class="row cl">
			<div class="col-9 col-offset-3">
				<button type="button" onclick="submitBtn()" class="btn btn-success radius" id="admin-role-save" name="admin-role-save">
						<i class="icon-ok"></i> 确定
				</button>
				<button type="button" onclick="layer_close()" class="btn btn-success radius" id="admin-role-close"
						name="admin-role-close">
						<i class="icon-ok"></i>取消
					</button>
			</div>
		</div>
	</form>
</div>
<script type="text/javascript">
function submitBtn(){
	var couponName = $("#couponName").val();
	if(couponName == ""){
		layer.msg('优惠券名称不能为空', {
			icon : 1,
			time : 1000
		});
		return ;
	}
	var commentdatemin = $("#commentdatemin").val();
	if(commentdatemin == null || commentdatemin == ""){
		layer.msg('请选择优惠券有效时间', {
			icon : 1,
			time : 1000
		});
		return ;
	}
	var commentdatemax = $("#commentdatemax").val();
	if(commentdatemax == null || commentdatemax == ""){
		layer.msg('请选择优惠券有效时间', {
			icon : 1,
			time : 1000
		});
		return ;
	}
	var couponCount = $("#couponCount").val();
	if(couponCount == null || couponCount == ""){
		layer.msg('优惠券个数不能为空', {
			icon : 1,
			time : 1000
		});
		return ;
	}
	var type=$('input:radio[name="ccouponUsetype"]:checked').val();
	if(type == 1){
		var ccouponUseparam = $("#ccouponUseparam").val();
		if(ccouponUseparam == null || ccouponUseparam == "" ){
			layer.msg('请填写类型参数', {
				icon : 1,
				time : 1000
			});
			return ;
		}
	}
	if(type == 2){
		var logmin = $("#logmin").val();
		if(logmin == null || logmin == "" ){
			layer.msg('请类型参数的开始时间', {
				icon : 1,
				time : 1000
			});
			return ;
		}
		var logmax = $("#logmax").val();
		if(logmax == null || logmax == "" ){
			layer.msg('请类型参数的结束时间', {
				icon : 1,
				time : 1000
			});
			return ;
		}
		$("#ccouponUseparam").val(logmin+","+logmax);
	}
	if(type == 10){
		$("#ccouponUseparam").val;
	}
	$("#form-area-add").ajaxForm({
		success:function(data) {
			if(data == 200){
				layer.msg('添加成功!', {icon: 6,time:1000});
				window.parent.location.href="${basePath}/coupon/list.do";
			}else{
				layer.msg("系统异常", {icon: 5,time:1000});
			}
		},      
		dataType:"json"   
	}).submit(); 	
}
function priceN(id){
	if(id==1){
		$("#priceP").show();
		$("#timeP").hide();
	}
	if(id == 2){
		$("#priceP").hide();
		$("#timeP").show();
	}
	if(id == 10){
		$("#priceP").hide();
		$("#timeP").hide();
	}
}
</script>
</body>
</html>